<?php

namespace App\Models\Form;

use App\Models\ActivityUserList;
use Illuminate\Http\Request;

class LoginForm extends RootForm
{
    //
    public $aid;
    public $acc;
    public $pwd;
    public $vcode;

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        parent::validate([
            'aid' => $this->aid,
            'acc' => $this->acc,
            'pwd' => $this->pwd,
            'vcode' => $this->vcode
        ], [
            "aid" => "required|integer|exists:activitylist,id",
            "acc" => "required|max:30",
            "pwd" => "required|max:6",
            "vcode" => "required|alpha_num|min:6|max:6",
        ], [
            "required" => ":attribute验证失败",
            "aid.integer" => ":attribute类型验证失败",
            "aid.exists" => ":attribute不存在",
            "vcode.alpha_num" => ":attribute格式不正确",
            "vcode.min" => ":attribute最低6位字符",
            "vcode.max" => ":attribute最高6位字符",
        ], [
            "acc" => "账号",
            "pwd" => "密码",
            "aid" => "活动",
            "vcode" => "验证码",
        ]);
    }

    public function submit(Request $request)
    {
        $aid = $this->aid;
        $acc = $this->acc;
        $pwd = $this->pwd;
        $status = 1;
        if ($this->checkVCode($this->vcode)) {
            if (ActivityUserList::where(compact('aid', 'acc', 'pwd', 'status'))->exists()) {
                return true;
            } else {
                return true;
            }

        }
    }
}
